/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jsf.service;

import com.jsf.entity.OtherUser;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;


/**
 *
 * @author Admin
 */
@ManagedBean(name = "userService")
@ApplicationScoped
public class UserService {
    
    private static List<OtherUser> list = new ArrayList<OtherUser>();
    
    private List<OtherUser> okList = new ArrayList<OtherUser>();
    
    public List<OtherUser> createUser() {
        if(getList().isEmpty()){
            getList().add(new OtherUser("gang","22","wuhan",true));
        return getList();
        }
        return getList();
        
    }
    
    public void addUser(OtherUser user){
        getList().add(user);
    }

    void deleteUser(String[] name) {
        
       for(OtherUser user : getList()) {
            for(int i=0;i<name.length;i++){
                if(user.getName() == null ? name[i] == null : user.getName().equals(name[i])){
                    list.remove(user);
                }
            }
       }
    }

    /**
     * @return the list
     */
    public List<OtherUser> getList() {
        return list;
    }
    /**
     * @return the booolean
     */
    boolean deleteName(String deleteName) {
        for(OtherUser user : getList()) {
                if(user.getName() == null ? deleteName == null : user.getName().equals(deleteName)){
                    list.remove(user);
                    return true;
                }
                
        }
        return false;
       }
    
    
    //冷冻
    boolean changeUser(String[] name) {
        String changeName = name[0];
        for(OtherUser user : getList()) {
                if(user.getName() == null ? changeName == null : user.getName().equals(changeName)){
                    user.setStatus(false);
                    return true;
                }
                
        }
        return false;
    }
    //解冻
    boolean returnUser(String[] name) {
                String changeName = name[0];
        for(OtherUser user : getList()) {
                if(user.getName() == null ? changeName == null : user.getName().equals(changeName)){
                    user.setStatus(true);
                    return true;
                }
                
        }
        return false;
    }
}
    